import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * 自动生成类
 *
 * @author zhaohualuo
 * @date 2019/8/16
 **/
public class CodeGeneration {

    //main函数
    public static void main(String[] args) {

        AutoGenerator autoGenerator = new AutoGenerator();

        //全局配置
        GlobalConfig gc = new GlobalConfig();
        String oPath = "D:\\src";//得到当前项目的路径
        gc.setOutputDir(oPath + "/");   //生成文件输出根目录
        gc.setOpen(false);//生成完成后不弹出文件框
        gc.setFileOverride(true);  //文件覆盖
        gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
        gc.setEnableCache(false);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(false);// XML columList
        gc.setAuthor("likl");// 作者

        // 自定义文件命名，注意 %s 会自动填充表实体属性！
        gc.setServiceName("%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setMapperName("%sMapper");
        gc.setXmlName("%sMapper");
        autoGenerator.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.POSTGRE_SQL);   //设置数据库类型，我是postgresql
        dsc.setDriverName("org.postgresql.Driver");
        dsc.setUsername("postgres");
        dsc.setPassword("123456");
        dsc.setUrl("jdbc:postgresql://localhost:19200/msidb");  //指定数据库
        autoGenerator.setDataSource(dsc);
        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

//         配置自定义输出模板
//        指定自定义模板路径，注意不要带上.ftl/.vm 会根据使用的模板引擎自动识别
//         templateConfig.setEntity("templates/entity2.java");
//         templateConfig.setService();
//         templateConfig.setController();

        //templateConfig.setXml(null);
        autoGenerator.setTemplate(templateConfig);
        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);      // 表名生成策略
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 列名生成策略
        strategy.setInclude(new String[]{
                "eip_drying_temperature",
                "eip_inside_cleanliness",
                "eip_inside_temperature",
                "eip_inside_humidity",
                "eip_outside_cleanliness",
                "eip_outside_temperature",
                "eip_outside_humidity",
//                "eip_contact_box",
//                "eip_casing_bushing",
//                "eip_post_insulator",
//                "eip_circuit_breaker_trolley",
//                "eip_current_transformer",
//                "eip_potential_transformer",
//                "eip_surge_arrester",
//                "eip_live_display",
//                "eip_fuse",
//                "eip_busbar",
//                "eip_material_thickness",
//                "eip_main_circuit_resist",
//                "eip_mechanical_operation",
//                "eip_ah_mech_charact",
//                "eip_ah_power_freque",
//                "eip_static_contact",
//                "eip_moving_contact",
//                "eip_ah_light_impulse",
//                "eip_ah_partial_disch",
//                "eip_aux_circuit_insul",
//                "eip_electrical_interlock",

//                "eip_insulation_torsion",
//                "eip_insulation_tensile",
//                "eip_arc_contact",
//                "eip_nozzle",
//                "eip_operating_mechanism",
//                "eip_insulator",
//                "eip_expansion_joint",
//                "eip_control_cabinet",

//                "eip_sales_order",
//                "eip_production_schedule",
//                "eip_schedule_workorder",
//                "eip_schedule_operation",
//                "eip_temp"
//
                "eip_partial_discharges",
                "eip_lightning_impulse",
                "eip_power_frequency",
                "eip_mechanical_characteristics",

//                "eip_data_detailed_info",

//                "zpg_eip_zhdq_hgjwd" ,
//                "zpg_eip_zhdq_wzjwd" ,
//                "zpg_eip_zhdq_wzjsd" ,
//                "zpg_eip_zhdq_wzjjjd" ,
//                "zpg_eip_zhdq_nzjwd" ,
//                "zpg_eip_zhdq_nzjsd" ,
//                "zpg_eip_zhdq_nzjjjd" ,
//                "zpg_eip_zhdq_jxtx" ,
//                "zpg_eip_zhdq_jbfd" ,
//                "zpg_eip_zhdq_ldcjsy" ,
//                "zpg_eip_zhdq_gpnsdy" ,
//                "zpg_eip_dlq_gpnsdy" ,
//                "zpg_eip_dlq_hgjwd" ,
//                "zpg_eip_dlq_jbfd" ,
//                "zpg_eip_dlq_jxtx" ,
//                "zpg_eip_dlq_ldcjsy" ,
//                "zpg_eip_dlq_nzjjjd" ,
//                "zpg_eip_dlq_nzjsd" ,
//                "zpg_eip_dlq_nzjwd" ,
//                "zpg_eip_dlq_wzjjjd" ,
//                "zpg_eip_dlq_wzjsd" ,
//                "zpg_eip_dlq_wzjwd" ,
//                "zpz_eip_zhdq_gpnsdy" ,
//                "zpz_eip_zhdq_hgjwd" ,
//                "zpz_eip_zhdq_jbfd" ,
//                "zpz_eip_zhdq_jxtx" ,
//                "zpz_eip_zhdq_ldcjsy" ,
//                "zpz_eip_zhdq_nzjjjd" ,
//                "zpz_eip_zhdq_nzjsd" ,
//                "zpz_eip_zhdq_nzjwd" ,
//                "zpz_eip_zhdq_wzjjjd" ,
//                "zpz_eip_zhdq_wzjsd" ,
//                "zpz_eip_zhdq_wzjwd"
        });     // 需要生成的表
        strategy.setSuperServiceClass(null);
        strategy.setSuperServiceImplClass(null);
        strategy.setSuperMapperClass(null);
        strategy.setEntityLombokModel(true);
        autoGenerator.setStrategy(strategy);

        // 包配置
        PackageConfig pc = new PackageConfig();
//        pc.setParent("com.pg.pg");
//        pc.setController("controller");
//        pc.setService("service");
//        pc.setServiceImpl("service.impl");
//        pc.setMapper("mapper");
        pc.setEntity("entity");
//        pc.setXml("mapper.xml");
        autoGenerator.setPackageInfo(pc);
        // 执行生成
        autoGenerator.execute();
    }
}
